package com.lmonkey.servlet.product;

import com.lmonkey.servic.PRODUCTDao;
import com.lmonkey.shop.PRODUCT;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/admin/admin_productselect")
public class ProductSelect extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //制作分页
        int cpage = 1;//当前页
        int count = 5;//每页显示
        String cp = request.getParameter("cp");
        //获取关键字
        String keyword = request.getParameter("keywords");

        if (cp != null){
            cpage = Integer.parseInt(cp);
        }

        int arr[] = PRODUCTDao.totalpage(count,keyword);

        ArrayList<PRODUCT> plist = PRODUCTDao.selectAll(cpage,count,keyword);

        request.setAttribute("plist",plist);
        request.setAttribute("total",arr[0]);
        request.setAttribute("count",arr[1]);
        request.setAttribute("cpage",cpage);

        if (keyword!=null){
            request.setAttribute("searchParams","&keywords="+keyword);
        }
            request.getRequestDispatcher("admin_product.jsp").forward(request,response);

    }
}
